package com.csproj.basic.repository;

import com.csproj.basic.domain.Warehouse;
import com.csproj.basic.repository.custom.WarehouseRepositoryCustom;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;
import java.util.List;

/**
 * Spring Data JPA repository for the Warehouse entity.
 */
@SuppressWarnings("unused")
@Repository
public interface WarehouseRepository extends JpaRepository<Warehouse, String> , WarehouseRepositoryCustom {
    /**
     * 根据ids查询机构信息
     * @author LM
     * @date   2017-12-04
     * @param ids
     * @return
     */
    @Query(" from Warehouse where id in (?1) ")
    List<Warehouse> findByIds(String[] ids);

    /**
     * 根据ids查询机构信息
     * @author LM
     * @date   2017-12-04
     * @return
     */
    @Query(" from Warehouse where deletedFlag = 0 and enableFlag = 1")
    List<Warehouse> findAllEnabled();


    /**
     * 根据ID删除数据
     * @author LM
     * @date   2017-12-04
     * @param id 机构id
     */
    @Modifying
    @Query("UPDATE Warehouse SET deletedFlag = 1 where id = ?1")
    void delete(String id);

    /**
     * 根据ID删除数据
     * @author LM
     * @date   2017-12-04
     * @param id 机构id
     */
    @Query(" from Warehouse where deletedFlag = 0 and id = ?1")
    Warehouse findById(String id);

    /**
     * findByName
     * @param name
     * @return
     */
    Warehouse findFirstByHouseNameAndDeletedFlagIsFalse(String name);

    @Query(" from Warehouse where deletedFlag = 0 and siteId = ?1")
    List<Warehouse> findWarehousesBySiteId(String siteId);

    /**
     * 根据机构ids，批量删除机构信息
     * @param ids
     */
    @Modifying
    @Query(" update Warehouse set deletedFlag = 1 where id in (?1) ")
    void deleteIds(String[] ids);
}
